package com.yoso.shop.infrastructure.base.controller;

import com.github.pagehelper.PageInfo;
import com.yoso.shop.infrastructure.base.entity.BaseEntity;
import com.yoso.shop.infrastructure.base.page.SearchParam;
import com.yoso.shop.infrastructure.base.pojo.PagePojo;
import com.yoso.shop.infrastructure.base.vo.BaseVo;
import com.yoso.shop.infrastructure.base.vo.PageVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.*;

/**
 * @author shizejin
 * @date 2021/11/9
 * @description:
 */
public abstract class BaseController<V extends BaseVo, E extends BaseEntity> extends AbstractBaseController<V, E> {

    /**
     * 条件分页查询
     */
    @PostMapping("/pageConditionsList")
    public BaseResponse<PageInfo<E>> pageConditionsList(@RequestBody PageVo pageVo) {
        PageInfo<E> result = this.getService().pageConditionsList(pageVo);
        return this.success("查询成功",result);
    }

    @ApiOperation("新增/修改")
    @PostMapping("/saveOrUpdate")
    public BaseResponse<Void> saveOrUpdate(@RequestBody V vo) {
        int result = this.getService().insertSelective(V2E(vo));
        return this.result(result);
    }
    @ApiOperation("查询全部")
    @GetMapping("/listAll")
    public BaseResponse<List<V>> listAll() {
        List<E> result = this.getService().listAll();
        return this.success("操作成功",bachE2V(result));
    }

}
